<template>
	<view class="page">
		<view class="head">
			<view class="head1">
				<text class="iconfont icon-fenxiang1"  @click="goBack"></text>
				<text class="nav-title">设置</text>
				
			</view>
		</view>
		<view class="nulldata"></view>
		<view class="main">
			<view class="items"> <text>页面置灰</text> <switch :checked="switch1Checked" @change="switch1Change"/></view>
			<view class="items"> <text>成为商家</text> <switch :checked="switch1Checked1" @change="switch1Change1"/></view>
			
			<view class="items" @click="handleLogout"> 退出登录</view>
				
			
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			const gray = uni.getStorageSync('moduleA_gray_scale');
			console.log(gray,'======')
			return{
				switch1Checked: !!uni.getStorageSync('moduleA_gray_scale')?true:false,
				switch1Checked1: Number(uni.getStorageSync('_UserInfo').level) === 1?true:false,
				userinfo: uni.getStorageSync('_UserInfo')
				}
			},
		
		methods:{
				switch1Change(e){
					// console.log(`发生change事件，携带值为`, e.detail.value)
					     uni.setStorageSync('moduleA_gray_scale', e.detail.value)
				},
				switch1Change1(e){
					this.userinfo['level'] = Number(e.detail.value)
					// console.log(`发生change事件，携带值为`, e.detail.value)
					     uni.setStorageSync('_UserInfo',this.userinfo)
				},
				
			handleLogout() {
				const _this = this;
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: async (res) => {
						if (res.confirm) {
							uni.showLoading();
							uni.setStorageSync('_login',false)
							await new Promise(resolve => setTimeout(resolve, 1000))
							// 执行退出登录
							uni.hideLoading();
							_this.goBack();
							
						}
					}
				})
			},
			goBack(){
					uni.navigateBack(-1)
			},
		
		}
	}
	
</script>

<style scoped lang="scss">
@import "collection.scss";
.page{
	height: 100vh;
	// max-height: 100vh;
	background-color: #f3f3f3;
	padding: 0;
	.nulldata{
		width: 100%;
		height: 200rpx;
	}
	.main{
		margin: 0;
		padding: 0 20rpx;
		padding-top: 20rpx;
	background-color: #f3f3f3;
		.items{
			padding-left: 30rpx;
			height: 70rpx;
			line-height: 70rpx;
			margin-bottom: 20rpx;
			background: #ffffff;
			border-radius: 6px;
			box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.16);
			text{
				margin-right: 30rpx;
			}
			
		}
	}
}
</style>